package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.NewsAuthDto;
import com.heima.model.wemedia.dto.WmNewsDto;
import com.heima.model.wemedia.dto.WmNewsPageReqDto;
import com.heima.model.wemedia.entity.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Resource
    private WmNewsService wmNewsService;

    /**
     * 发布文章
     * @param dto
     * @return
     */
    @PostMapping("submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto){
        return wmNewsService.submit(dto);
    }

    /**
     * 文章内容列表展示
     * @param dto
     * @return
     */
    @PostMapping("list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto dto){
        return wmNewsService.list(dto);
    }

    /**
     * 编辑文章
     * @param id
     * @return
     */
    @GetMapping("one/{id}")
    public ResponseResult one(@PathVariable Long id){
        WmNews wmNews = wmNewsService.queryById(id);
        return ResponseResult.okResult(wmNews);
    }

    /**
     * 删除文章
     * @param id
     * @return
     */
    @GetMapping("del_news/{id}")
    public ResponseResult deleteNews(@PathVariable Long id){
        return wmNewsService.deleteById(id);
    }

    /**
     * 运营管理文章内容列表展示
     * @param dto
     * @return
     */
    @PostMapping("list_vo")
    public ResponseResult list_vo(@RequestBody NewsAuthDto dto){
        return wmNewsService.list_vo(dto);
    }

    /**
     * 运营管理查询文章内容详情
     * @param id
     * @return
     */
    @GetMapping("one_vo/{id}")
    public ResponseResult one_vo(@PathVariable Long id){
        return wmNewsService.one_vo(id);
    }

    /**
     * 审核失败
     * @param dto
     * @return
     */
    @PostMapping("auth_fail")
    public ResponseResult auth_fail(@RequestBody NewsAuthDto dto){
        return wmNewsService.ManualAudit(dto);
    }

    /**
     * 审核通过
     * @param dto
     * @return
     */
    @PostMapping("auth_pass")
    public ResponseResult auth_pass(@RequestBody NewsAuthDto dto){
        return wmNewsService.ManualAudit(dto);
    }


}
